<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<script type="text/javascript" src="jquery/jquery-1.10.2.js"></script>
<script type="text/javascript" src="md5/md5.js"></script>
	<style type="text/css">
	</style>
	<script type="text/javascript">
		$(document).ready(function(){
			//tab
			window.setTab=function(name,cursel,n){
				 for(i=1;i<=n;i++){
				  var menu=document.getElementById(name+i);
				  var con=document.getElementById("con_"+name+"_"+i);
				  menu.className=i==cursel?"hover":"";
				  con.style.display=i==cursel?"block":"none";
				 }
				}
			
			$("#submit").click(function(){
				var form = document.getElementById("feedForm");
				var latlng = form.latlng.value;
				var title=form.title.value;
				var content=form.content.value;
				var url = "http://map.baidu.com/?latlng="+latlng+"&title="+title+"&content="+content+"&autoOpen=true&l=";
			    location.href = url;
			});
			$("#accesssubmit").click(function(){
				var form = document.getElementById("accessForm");
				$.ajax({
					url:"/open/oauth/access_token",
					//url:"http://10.10.62.117:8080/login?api_login=true",
					//url:"http://127.0.0.1:8088/cas/api/account/checklogin",
					type:"post",
					data:$("#accessForm").serialize(),
					success:function(r){
						//console.log(r);
						//alert(r.message);
						$("#access_token").html(JSON.stringify(r));
						//alert(r.data.SESSION_TOKEN);
					}
				});
			});
			$("#authCodeSubmit").click(function(){
				var form = document.getElementById("authCodeForm");
				$.ajax({
					url:"/open/oauth/access_token",
					//url:"http://10.10.62.117:8080/login?api_login=true",
					//url:"http://127.0.0.1:8088/cas/api/account/checklogin",
					type:"post",
					data:$("#authCodeForm").serialize(),
					success:function(r){
						//console.log(r);
						//alert(r.message);
						$("#authCodeSpan").html(JSON.stringify(r));
						//alert(r.data.SESSION_TOKEN);
					}
				});
			});
			$("#implicitSubmit").click(function(){
				/*var form = document.getElementById("implicitForm");
				$.ajax({
					url:"/open/oauth/authorize",
					//url:"http://10.10.62.117:8080/login?api_login=true",
					//url:"http://127.0.0.1:8088/cas/api/account/checklogin",
					type:"get",
					data:$("#implicitForm").serialize(),
					success:function(r){
						//console.log(r);
						//alert(r.message);
						$("#implicitSpan").html(JSON.stringify(r));
						//alert(r.data.SESSION_TOKEN);
					}
				});
				*/
				var form = document.getElementById("implicitForm");
				var client_id = form.client_id.value;
				//var client_secret = form.client_secret.value;
				var redirect_uri = form.redirect_uri.value;
				var response_type= form.response_type.value;
				//var auth_code= form.auth_code.value;
				
				window.open('/open/oauth/authorize?client_id='+client_id+'&response_type='+response_type+'&scope=all&redirect_uri='+redirect_uri, 'oauth2Login_10041' ,'height=525,width=585, toolbar=no, menubar=no, scrollbars=no, status=no, location=yes, resizable=yes');

			});
			$("#getUserSubmit").click(function(){
				var form = document.getElementById("getUserForm");
				$.ajax({
					url:"/open/user/get_userinfo",
					//url:"http://10.10.62.117:8080/login?api_login=true",
					//url:"http://127.0.0.1:8088/cas/api/account/checklogin",
					type:"get",
					data:$("#getUserForm").serialize(),
					success:function(r){
						//console.log(r);
						//alert(r.message);
						$("#userInfo").html(JSON.stringify(r));
						//alert(r.data.SESSION_TOKEN);
					}
				});
			});
		});
		
		function doAjax(method,url,parm){
			$.ajax({
				url:url,
				type:method,
				data:parm,
				success:function(r){
					console.log(r);
					$("#resultTextarea").val(JSON.stringify(r));
				},
				error:function(XMLHttpRequest, textStatus, errorThrown){
					console.log(XMLHttpRequest.responseText);
					$("#resultTextarea").val(XMLHttpRequest.responseText);
				}
			});
		}
		function doJsonAjax(method,url,parm){
			$.ajax({
				url:url,
				type:method,
				contentType:"application/json",
				data:JSON.stringify(parm),
				success:function(r){
					console.log(r);
					$("#resultTextarea").val(JSON.stringify(r));
				},
				error:function(XMLHttpRequest, textStatus, errorThrown){
					console.log(XMLHttpRequest.responseText);
					$("#resultTextarea").val(XMLHttpRequest.responseText);
				}
			});
		}
		function checkLogin(){
			//getCookie("JSESSIONID");
				var form = document.getElementById("feedForm");
			var client_id = form.client_id.value;
			var redirect_uri = form.redirect_uri.value;
			var response_type= form.response_type.value;
			window.open('/open/oauth/authorize?client_id='+client_id+'&response_type='+response_type+'&scope=all&redirect_uri='+redirect_uri, 'oauth2Login_10041' ,'height=525,width=585, toolbar=no, menubar=no, scrollbars=no, status=no, location=yes, resizable=yes');
			//document.getElementById("iframe").src = "/open/oauth/authorize?client_id="+client_id+"&redirect_uri="+redirect_uri+"&response_type="+response_type;
		}
		function getAccessToken(){
			var form = document.getElementById("feedForm");
			var client_id = form.client_id.value;
			var client_secret = form.client_secret.value;
			var redirect_uri = form.redirect_uri.value;
			var response_type= form.response_type.value;
			var auth_code= form.auth_code.value;
			
			window.open('/open/oauth/access_token?client_id='+client_id+'&client_secret='+client_secret+'&code='+auth_code+'&grant_type=authorization_code&scope=all&redirect_uri='+redirect_uri, 'oauth2Login_10041' ,'height=525, toolbar=no, menubar=no, scrollbars=no, status=no, location=yes, resizable=yes');
	 }
	

		var url = "/open/pubservice/send?access_token=";
		var sendText = function() {
			var params = function() {
				var to = $("#to").val();
				var ids;
				if(to.indexOf(",") > -1) {
					ids = to.split(",");
				}
				if(ids) {
					return {
						filter : {
							toUserIds : ids
						},
						content : $("#message").val(),
						msgType :"text"
					}
				} else {
					return {
						toUserId : $("#to").val(),
						content : $("#message").val(),
						msgType :"text"
					}
				}
			}();
			post(url, params);
		}
		
		var sendImage = function() {
			var params = {
				toUserId : $("#to").val(),
				mimetype : $("#mimetype").val(),
				size : $("#size").val(),
				fId : $("#fId").val(),
				msgType :"image"
			}
			post(url, params);
		}
		
		var post = function(urlPrefix, params) {
			var jsonParams = JSON.stringify(params);
			$.ajax({
				url:urlPrefix + $("#accessToken").val(),
		        type: 'POST', 
		        contentType: "application/json",
		        data: jsonParams,
		        success: function(result) { 
		        	alert(result);
		        }
            });
		}
	</script>

<style type="text/css">
.table{
	border-collapse:collapse;
	width:700px;
}
.table td,.table th{
	border:1px solid #ccc;
}
input[type="text"]{
	width:300px;
}

body{ padding:10;font:12px "宋体";  margin-top:50px;}
/*选项卡1*/
#lib_Tab1_sx{width:90%;margin:0px;padding:0px;margin-bottom:15px; overflow:hidden;}
/*菜单class*/
.lib_tabborder_sx{border:1px solid #95C9E1;}
.lib_Menubox_sx {line-height:28px;position:relative; float:left; width:200px; height:240px;border-right:1px solid #95C9E1;}
.lib_Menubox_sx ul{margin:0px;padding:0px;list-style:none; position:absolute; top:15px; left:5px; margin-left:10px; height:25px;text-align:center;}
.lib_Menubox_sx li{display:block;cursor:pointer;width:184px;color:#949694;font-weight:bold; margin-bottom:5px;height:25px;line-height:25px; background-color:#E4F2FD}
.lib_Menubox_sx li.hover{padding:0px;background:#fff;width:186px;border:1px solid #95C9E1; border-right:0;
color:#739242;height:25px;line-height:25px;}
.lib_Contentbox_sx{margin-top:0px; border-top:none;padding:20px; border-left:0; margin-left:200px;}

</style>
</head>
<body>

<p style="margin-top:50px;">oauth:</p>
<div id="lib_Tab1_sx" class="lib_tabborder_sx">
<div class="lib_Menubox_sx ">
<ul>
   <li id="one1" onclick="setTab('one',1,6)" class="hover">授权码auth_code授权</li>
   <li id="one2" onclick="setTab('one',2,6)" >根据授权码获取AccessToken</li>
   <li id="one3" onclick="setTab('one',3,6)">根据AccessToken返回OpenId</li>   
   <li id="one4" onclick="setTab('one',4,6)">Client Credentials授权</li>
   <li id="one5" onclick="setTab('one',5,6)">获取用户信息</li>
   <li id="one6" onclick="setTab('one',6,6)">隐式登录授权</li>
</ul>
</div>
 <div class="lib_Contentbox_sx ">  
   <div id="con_one_1" >
      <form id="feedForm" method="post">
      	<table>
      		<tr>
      			<td>client_id:</td>
      			<td><input type="text" name="client_id" value="00014645948fcf00"/></td>
      		</tr>
      		<tr>
      			<td>client_secret:</td>
      			<td><input type="text" name="client_secret" value="68c56776a93545b2896d1236fb538475"/></td>
      		</tr>
      		<tr>
      			<td>redirect_uri:</td>
      			<td><input type="text" name="redirect_uri" value="http://127.0.0.1:8080/admin"/></td>
      		</tr>
      		<tr>
      			<td>response_type:</td>
      			<td><input type="text" name="response_type" value="code"/></td>
      		</tr>
      		<tr>
      			<td>使用企信登录:</td>
      			<td><img src="logo2oauth.jpg" width="100" height="30" onclick="checkLogin()"/></td>
      		</tr>
      		<tr>
      			<td colspan="5"><hr width="90%"/></td>
      		</tr>
      		<tr>
      			<td colspan="2"><input type="text" name="auth_code" value="00014645948fcf00"/></td>
      			<td><input type="button" onclick="getAccessToken()" value="获取access token"/> </td>
      		</tr>
      	</table>
       </form>    
   </div>
   <div id="con_one_2" style="display:none">
	   	<form id="authCodeForm" method="post">
	   		<table>
      			<tr>
      				<td>client_id:</td>
      				<td><input type="text" name="client_id" value="00014645948fcf00"/></td>
      			</tr>
      			<tr>
      				<td>client_secret:</td>
      				<td><input type="text" name="client_secret" value="68c56776a93545b2896d1236fb538475"/></td>
      			</tr>
      			<tr>
      				<td>grant_type:</td>
      				<td><input type="text" name="grant_type" value="authorization_code"/></td>
      			</tr>
      			<tr>
      				<td>code:</td>
      				<td><input type="text" name="code" value=""/></td>
      			</tr>
      			<tr>
      				<td>redirect_uri:</td>
      				<td><input type="text" name="redirect_uri" value="http://127.0.0.1:8080/admin"/></td>
      			</tr>
      			<tr>
      				<td colspan="2"> 
      					<input type="button" id="authCodeSubmit"value="获取access token"/>：<span id="authCodeSpan"></span>
      				</td>
      			</tr>
       		</table>
	         
	   </form>
   </div>
   <div id="con_one_3" style="display:none">
   		<form id="authCodeForm" method="post">
   			<table>
   				<tr>
   					<td>client_id:</td>
   					<td><input type="text" name="client_id" value="00014645948fcf00"/></td>
   				</tr>
   				<tr>
   					<td>client_secret:</td>
   					<td><input type="text" name="client_secret" value="68c56776a93545b2896d1236fb538475"/></td>
   				</tr>
   				<tr>
   					<td>grant_type:</td>
   					<td><input type="text" name="grant_type" value="authorization_code"/></td>
   				</tr>
   				<tr>
   					<td>code:</td>
   					<td><input type="text" name="code" value=""/></td>
   				</tr>
   				<tr>
   					<td>redirect_uri:</td>
   					<td><input type="text" name="redirect_uri" value="http://127.0.0.1:8080/admin"/></td>
   				</tr>
   				<tr>
      				<td colspan="2"> 
      					<input type="button" id="authCodeSubmit"value="获取access token"/>：<span id="authCodeSpan"></span>
      				</td>
      			</tr>
   			</table>
   	</form>
   </div>
   <div id="con_one_4" style="display:none">
   		<form id="accessForm" method="get">
   			<table>
   				<tr>
   					<td>client_id:</td>
   					<td ><input type="text" name="client_id" value="00014645948fcf00"/></td>
   				</tr>
   				<tr>
   					<td>client_secret:</td>
   					<td><input type="text" name="client_secret" value="5729e757d9b947279503f48c737938b4"/></td>
   				</tr>
   				<tr>
   					<td>grant_type:</td>
   					<td><input type="text" name="grant_type" value="client_credentials"/></td>
   				</tr>
   				<tr>
   					<td>scope:</td>
   					<td><input type="text" name="scope" value="all"/></td>
   				</tr>
   				<tr>
   					<td>access_level:</td>
   					<td>
   						<select name="access_level"><option value="0">测试用户</option><option value="1">普通用户</option><option value="2">高级用户</option><option value="3">合作用户</option></select>
   					</td>
   				</tr>
   				<tr>
      				<td colspan="2"> 
      					<input type="button" id="accesssubmit"value="获取access token"/>
      				</td>
      			</tr>
      			<tr>
      				<td colspan="2"> 
      					<span id="access_token"></span>
      				</td>
      			</tr>
   			</table>
   	  </form>  	
   </div> 
   <div id="con_one_5" style="display:none">
  	  <form id="getUserForm" method="get">
  	  	<table>
  	  		<tr>
  	  			<td>access_token:</td>
  	  			<td><input type="text" name="access_token" value="00014645948fcf00"/></td>
  	  		</tr>
  	  		<tr>
  	  			<td>userId:</td>
  	  			<td><input type="text" name="userId" value="00014645948fcf00"/></td>
  	  		</tr>
  	  		<tr>
  				<td colspan="2"> 
  					<input type="button" id="getUserSubmit"value="获取用户信息"/>
  				</td>
  			</tr>
  			<tr>
  				<td colspan="2"> 
  					<span id="userInfo"></span>
  				</td>
  			</tr>
  	  	</table>
	   </form>
   </div> 
     <div id="con_one_6" style="display:none">
  	<form id="implicitForm" method="get">
  	  	<table>
  	  		<tr>
  	  			<td>client_id:</td>
  	  			<td><input type="text" name="client_id" value="00014645948fcf00"/></td>
  	  		</tr>
  	  		<tr>
  	  			<td>redirect_uri:</td>
  	  			<td><input type="text" name="redirect_uri" value="http://www.baidu.com"/></td>
  	  		</tr>
  	  		<tr>
  	  			<td>response_type:</td>
  	  			<td><input type="text" name="response_type" value="token"/></td>
  	  		</tr>
  	  		<tr>
  	  			<td>scope:</td>
  	  			<td><input type="text" name="scope" value="all"/></td>
  	  		</tr>
  	  		<tr>
  				<td colspan="2"> 
  					<input type="button" id="implicitSubmit"value="获取access token"/>
  				</td>
  			</tr>
  			<tr>
  				<td colspan="2"> 
  					<span id="implicitSpan"></span>
  				</td>
  			</tr>
  	  	</table>
	   </form>
   </div> 
 </div>
</div>

<p style="margin-top:50px;">发送消息</p>
<p >填写申请的access_token：<input id="accessToken" type="text" name="access_token"/></p>
<div id="lib_Tab1_sx" class="lib_tabborder_sx">
<div class="lib_Menubox_sx">
<ul>
   <li id="two1" onclick="setTab('two',1,2)" class="hover">文本消息</li>
   <li id="two2" onclick="setTab('two',2,2)" >图片消息</li>
</ul>
</div>
 <div class="lib_Contentbox_sx ">  
   <div id="con_two_1" >
   		<table>
   			<tr>
   				<td>to:</td>
   				<td><input id="to" type="text" name="to"/></td>
   			</tr>
   			<tr>
   				<td>message:</td>
   				<td><input id="message" type="text" name="message" /></td>
   			</tr>
   			<tr>
   				<td colspan="2"><button onclick="sendText();">发送</button></td>
   			</tr>
   		</table>
   </div>
   <div id="con_two_2" style="display:none">
   		<table>
   			<tr>
   				<td>mimetype:</td>
   				<td><input id="mimeType" type="text" name="mimeType" value="image/jpg"/></td>
   			</tr>
   			<tr>
   				<td>size:</td>
   				<td><input id="size" type="text" name="size" /></td>
   			</tr>
   			<tr>
   				<td>fId:</td>
   				<td><input id="fId" type="text" name="fId"/></td>
   			</tr>
   			<tr>
   				<td colspan="2"><button onclick="sendImage();">发送</button></td>
   			</tr>
		</table>
   </div>
 </div>
</div>
<!-- 
<fieldset>
   <legend>Oauth</legend>
   <form id="feedForm" method="post">
        client_id:<input type="text" name="client_id" value="00014645948fcf00"/><br/>
         client_secret:<input type="text" name="client_secret" value="68c56776a93545b2896d1236fb538475"/><br/>
        redirect_uri:<input type="text" name="redirect_uri" value="http://127.0.0.1:8080/admin"/><br/>
        response_type:<input type="text" name="response_type" value="code"/><br/>
		使用企信登录:<img src="logo2oauth.jpg" width="100" height="30" onclick="checkLogin()"/><br/>
	
    <br/><br/><br/>
             <input type="text" name="auth_code" value="00014645948fcf00"/><br/>
     <input type="button" onclick="getAccessToken()" value="获取access token"/>        
          </form>    
   <br/><br/><br/>
  
</fieldset>

<fieldset>
   <legend>根据auth_code返回AccessToken</legend>
   <form id="authCodeForm" method="post">
        client_id:<input type="text" name="client_id" value="00014645948fcf00"/><br/>
         client_secret:<input type="text" name="client_secret" value="68c56776a93545b2896d1236fb538475"/><br/>
         grant_type:<input type="text" name="grant_type" value="authorization_code"/><br/>
         code:<input type="text" name="code" value=""/><br/>
         redirect_uri:<input type="text" name="redirect_uri" value="http://127.0.0.1:8080/admin"/><br/>
          <input type="button" id="authCodeSubmit"value="获取access token"/>：<span id="authCodeSpan"></span>
   </form>
</fieldset> 
<fieldset>
   <legend>根据AccessToken返回OpenId</legend>
   <form id="authCodeForm" method="post">
        client_id:<input type="text" name="client_id" value="00014645948fcf00"/><br/>
         client_secret:<input type="text" name="client_secret" value="68c56776a93545b2896d1236fb538475"/><br/>
         grant_type:<input type="text" name="grant_type" value="authorization_code"/><br/>
         code:<input type="text" name="code" value=""/><br/>
         redirect_uri:<input type="text" name="redirect_uri" value="http://127.0.0.1:8080/admin"/><br/>
          <input type="button" id="authCodeSubmit"value="获取access token"/>：<span id="authCodeSpan"></span>
   </form>
</fieldset> 

<fieldset>
   <legend>implicit_grant方式获取access_token</legend>
   <form id="implicitForm" method="get">
       client_id:<input type="text" name="client_id" value="00014645948fcf00"/><br/>
       redirect_uri:<input type="text" name="redirect_uri" value="http://www.baidu.com"/><br/>
       response_type:<input type="text" name="response_type" value="token"/><br/>
        scope:<input type="text" name="scope" value="all"/> <br/>
        <input type="button" id="implicitSubmit"value="获取access token"/>：<span id="implicitSpan"></span>
   </form>  
</fieldset>  

<fieldset>
   <legend>Client Credentials授权</legend>
   <form id="accessForm" method="get">
       client_id:<input type="text" name="client_id" value="00014645948fcf00"/><br/>
       client_secret:<input type="text" name="client_secret" value="5729e757d9b947279503f48c737938b4"/><br/>
       grant_type:<input type="text" name="grant_type" value="client_credentials"/><br/>
        scope:<input type="text" name="scope" value="all"/> <br/>
         access_level:<select name="access_level"><option value="0">测试用户</option><option value="1">普通用户</option><option value="2">高级用户</option><option value="3">合作用户</option></select><br/>
        <input type="button" id="accesssubmit"value="获取access token"/>：<span id="access_token"></span>
   </form>  
</fieldset>   
<fieldset>
   <legend>获取用户信息</legend>
   <form id="getUserForm" method="get">
    access_token:<input type="text" name="access_token" value="00014645948fcf00"/><br/>
    userId:<input type="text" name="userId" value="00014645948fcf00"/><br/>
     <input type="button" id="getUserSubmit"value="获取用户信息"/>：<span id="userInfo"></span>
   </form>
   
 </fieldset> 
 -->
</body>
</html>
